package com.eternal.base;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;

import com.alibaba.android.arouter.launcher.ARouter;
import com.clj.fastble.BleManager;
import com.clj.fastble.scan.BleScanRuleConfig;
import com.eternal.base.global.BluetoothKey;
import com.eternal.framework.utils.KLog;

import java.util.UUID;

import io.reactivex.functions.Consumer;
import io.reactivex.plugins.RxJavaPlugins;

/**
 * @author li
 */
public class BaseModuleInit implements IModuleInit {
    @Override
    public boolean initAhead(Application application) {
        KLog.init(true);
        if(BuildConfig.DEBUG){
            ARouter.openDebug();
            ARouter.openLog();
        }
        ARouter.init(application);
        BleManager.getInstance().init(application);
        BleManager.getInstance().setReConnectCount(0);
        initChannel(application);
        RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                throwable.printStackTrace();
                KLog.e(throwable);
            }
        });
        KLog.i("base library init");
        return false;
    }

    private void initChannel(Application application){
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationManager manager= (NotificationManager) application.getSystemService(Context.NOTIFICATION_SERVICE);
            String id="notification";
            NotificationChannel channel=new NotificationChannel(id, "notification", NotificationManager.IMPORTANCE_HIGH);
            channel.setShowBadge(true);
            manager.createNotificationChannel(channel);
        }
    }

    @Override
    public boolean initLow(Application application) {
        return false;
    }
}
